﻿package net.wangit.user.privilege;

import net.wangit.framework.cache.Cache;
import net.wangit.framework.util.CacheUtil;

public class DataPrivilegeCache {

	public DataPrivilegeCache() {
	}

	public static DataPrivilege get(String domain, String privilegeType,
			String resourceId) {
		String key = getKey(privilegeType, resourceId);
		return (DataPrivilege) getCache(domain).get(key);
	}

	public static void put(String domain, String privilegeType,
			String resourceId, DataPrivilege dp) {
		String key = getKey(privilegeType, resourceId);
		getCache(domain).put(key, dp);
	}

	public static void clear(String domain, String privilegeType,
			String resourceId) {
		String key = getKey(privilegeType, resourceId);
		getCache(domain).clear(key);
	}

	public static void clearAll(String domain) {
		getCache(domain).clearAll();
	}

	private static Cache getCache(String domain) {
		return CacheUtil.getDataPrivilegeCache(domain);
	}

	private static String getKey(String privilegeType, String resourceId) {
		return (new StringBuilder(String.valueOf(privilegeType))).append(",")
				.append(resourceId).toString();
	}
}
